package com.k8s.base.web;

import com.k8s.base.DummyConfig;
import com.k8s.base.domain.Dict;
import com.k8s.base.repository.DictRepository;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;

@RestController
@RequestMapping("global")
public class GlobalResource {

    private final DummyConfig dummyConfig;

    private final DictRepository dictRepository;

    public GlobalResource(DummyConfig dummyConfig, DictRepository dictRepository) {
        this.dummyConfig = dummyConfig;
        this.dictRepository = dictRepository;
    }

    @GetMapping("config")
    public ResponseEntity<HashMap<String, Object>> getConfig(){
        return ResponseEntity.ok(
            new HashMap<String,Object>(){{
                put("name",dummyConfig.getMessage());
            }}
        );
    }

    @GetMapping("dicts")
    public ResponseEntity<List<Dict>> getDict(){
        return ResponseEntity.ok(dictRepository.findAll());
    }
}
